package com.qububu.common.user.dto;

import java.io.Serializable;
import java.util.Arrays;

import com.qububu.utils.DateUtil;
import com.qububu.utils.SystemUtil;

/**
 * 针对客户端所需用户Dto(所有数据均处理完毕, 页面直接拿到使用即可)
 * 
 * @author 
 */
public class UserInfoDto implements Cloneable, Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -692689982993940242L;
	
	private Sex userSex;
	private int userBirthday;
	private int userRegistDttm;
	private String userRegistIp;
	private String userEamil;
	private String userId;
	private String nickName;
	private String userLogoUrl;
	private String positionId;
	
	public String getPositionId() {
		return positionId;
	}

	public String getUserId() {
		return userId;
	}
	
	public String getNickName() {
		return nickName;
	}
	public void setNickName(String nickName) {
		this.nickName = nickName;
	}
	public String getUserLogoUrl() {
		return userLogoUrl;
	}
	public void setUserLogoUrl(String userLogoUrl) {
		this.userLogoUrl = userLogoUrl;
	}
	public Sex getUserSex() {
		return userSex;
	}
	public void setUserSex(Sex userSex) {
		this.userSex = userSex;
	}
	public int getUserBirthday() {
		return userBirthday;
	}
	public void setUserBirthday(int userBirthday) {
		this.userBirthday = userBirthday;
	}
	public int getUserRegistDttm() {
		return userRegistDttm;
	}
	public void setUserRegistDttm(int userRegistDttm) {
		this.userRegistDttm = userRegistDttm;
	}
	public String getUserRegistIp() {
		return userRegistIp;
	}
	public void setUserRegistIp(String userRegistIp) {
		this.userRegistIp = userRegistIp;
	}
	
	public String getUserEamil() {
		return userEamil;
	}
	public void setUserEamil(String userEamil) {
		this.userEamil = userEamil;
	}
	
	/**
	 * @功能 生日以String格式显示, 针对跳转
	 * */
	public String showBirthdayInString() {
		return DateUtil.formatDTString(userBirthday);
	}
	
	/**
	 * @功能 注册时间以String格式显示, 针对跳转
	 * */
	public String showRegisterDateInString() {
		return DateUtil.formatToDTTMString(userRegistDttm);
	}
	
	/**
	 * @param userId 加密型userId
	 * @param positionId 加密型positionId
	 * */
	public UserInfoDto(String userId, String positionId) {
		this.userId = userId;
		this.positionId = positionId;
	}
	
	/**
	 * @param userId 真正的userId
	 * @param positionId 真正的positionId
	 * */
	public UserInfoDto(long userId, long positionId) {
		
		this.userId = SystemUtil.encrypt(String.valueOf(userId) );
		this.positionId = SystemUtil.encrypt(String.valueOf(positionId) );
	}
	
	/**
	 * @param userId 真正的userId
	 * @param positionId 加密的positionId
	 * */
	public UserInfoDto(long userId, String positionId) {
		
		this.userId = SystemUtil.encrypt(String.valueOf(userId) );
		this.positionId = positionId;
	}
	
	@Override
	public UserInfoDto clone() {
		UserInfoDto newInfo = new UserInfoDto(userId, positionId);
		newInfo.setUserSex(userSex);
		newInfo.setUserBirthday(userBirthday);
		newInfo.setUserRegistDttm(userRegistDttm);
		newInfo.setUserRegistIp(userRegistIp);
		
		return newInfo;
	}
	
	public enum Sex {
		MALE(0),
		FEMALE(1);
		
		private int intValue;
		
		private Sex(int intValue) {
			this.intValue = intValue;
		}
		
		/**
		 * 根据传入字符串来返回对应的状态类型
		 */
		public static Sex getSex(String strValue) {
			try {
				Sex type = valueOf(strValue);
				return type;
			}
			catch(Exception ex) {
				throw new IllegalArgumentException("Value '" + strValue + "' is not allowed in Sex. Only "
						+ Arrays.toString(Sex.values()) + " are allowed."
						);
			}
		}
		
		/**
		 * 根据传入INT值来返回对应的状态类型
		 */
		public static Sex getSex(int intValue) {
			for (Sex elem : Sex.values()) {
				if (elem.toIntValue() == intValue) {
					return elem;
				}
			}

			throw new IllegalArgumentException("Value '" + intValue
					+ "' is not allowed in Sex.");
		}

		/**
		 * 返回int值类型。
		 * @return
		 */
		public int toIntValue() {
			return intValue;
		}
	}

}
